﻿/*
* 控制 MovieClip 上之 Label 播放方式
* EX 版, 向上支援 SmartClipBase
* 新增 playOrder(['frame1','frame2','frame4','frame3','frame1']:Array) 無長度限制Array.順序播放.
* 
* By Canis. 20091007

20110113 修正小錯誤,
bugs : playOrder 不能被強制停止
playOrder 使用 UIEvent.EVENT 作 next clip 判斷

*/
package com.cf.core.model{
	import flash.display.MovieClip;
	import flash.display.SimpleButton; // fix CS3 bug
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import com.cf.core.Utils.tools;
	import com.cf.core.events.UIEvent;
	import com.cf.core.model.SmartClipBase;
	import flash.display.FrameLabel;
	public class SmartClipEX extends SmartClipBase{
		static const ORDER:String = "SmartClipPlayOrder";
		static const PLAYUNTIL:String = "SmartClipPlayUntil";
		
		private var __OrderObject:Array;
		private var __OrderPointer:int;
		
		public function SmartClipEX():void{	}//fn
		public function playOrder(_arr:Array):void{
			var _Qobj:Object;
			__OrderObject=new Array();
			for(var i:int=0; i<_arr.length; i++){
				_Qobj = labelLength(_arr[i]);
				if(_Qobj.exist)	__OrderObject[__OrderObject.length]=_Qobj;
			}//for
			__OrderPointer=0;
			internal=true; // turn on the internal mode.
			addEventListener(UIEvent.EVENT, handleOrder);
			playOne(__OrderObject[__OrderPointer].name);
		}//fn
		
		private function handleOrder(e:UIEvent):void{
			removeEventListener(UIEvent.EVENT, handleOrder);
			addEventListener(Event.ENTER_FRAME, handleTempCall)
		}//fn
		private function handleTempCall(e:Event):void{
			removeEventListener(Event.ENTER_FRAME, handleTempCall);
			if((__OrderPointer+1)<__OrderObject.length){
				// play before end of label order
				if(this.playingFrame==__OrderObject[__OrderPointer].name){
					// when the playing frame is same.
					// PS: it may change by user. stop it.
					addEventListener(UIEvent.EVENT, handleOrder);
					__OrderPointer++;
					playOne(__OrderObject[__OrderPointer].name);
				}//if
			}else{
				// No more Order left. dispatch / callback
				dispatchEvent(new UIEvent(UIEvent.LOADED, {action:ORDER}));
				internal=false; // turn off the internal mode.
			}//if
		}//fn
	}//class
}//package